import { Component } from '@angular/core';
import { NavController, NavParams, ViewController } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { User } from '../../providers/login-data/user';
import { UserSettingProvider } from '../../providers/user-setting/user-setting';

/**
 * Generated class for the SetPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-set',
  templateUrl: 'set.html',
})
export class SetPage {
  username: string;
  mobilePhoneNumber: string;
  belong: string;
  position: string;
  user: User;
  flag:boolean;
 

  constructor(public navCtrl: NavController,
    public navParams: NavParams,
    public viewCtrl: ViewController,
    storage: Storage,
    public http: UserSettingProvider,
  ) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad SetPage');
    this.username = localStorage.getItem("username");
    this.mobilePhoneNumber= localStorage.getItem('mobilePhoneNumber');
    this.belong = localStorage.getItem('belong');
    this.position = localStorage.getItem('position');
    let leval=localStorage.getItem('leval');
    if(leval=="0"){
      this.flag=false;
    }else{
      this.flag=true;
    }
console.log(leval);


  }
  close(){
    this.viewCtrl.dismiss();
  }

  saveUser() {
    let user: User = {
      username: this.username,
      mobilePhoneNumber: this.mobilePhoneNumber,
      belong: this.belong,
      position: this.position,
      objectId: localStorage.getItem('objectId'),
      sex: '',
      leval: '',
      sessionToken: '',
      mobilePhoneVerified: true,
      name: '',
      createdAt: '',
      updateAt: '',
      password: '',
    };
    this.http.updateUser(user).subscribe();
    this.viewCtrl.dismiss(user);
  }
}